package cn.zhonghuanzhiyuan.sprc.basicinfo.controller;



import cn.org.bachelor.web.json.JsonResponse;

import cn.zhonghuanzhiyuan.sprc.basicinfo.domain.EntDuty;

import cn.zhonghuanzhiyuan.sprc.basicinfo.pojo.vo.QueryEntDutyVo;

import cn.zhonghuanzhiyuan.sprc.basicinfo.service.EntDutyService;
import cn.zhonghuanzhiyuan.sprc.common.utils.excel.ExcelUtils;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

import java.util.List;

/**
 * @param
 * @author 涛哥
 * @version 1.0
 * @ClassName:Name
 * @description:企业值班值守信息管理
 * @date 2024/1/23 11:10
 */

@Api(tags = "企业值班值守信息管理")
@RestController
@RequestMapping("/duty")
@CrossOrigin // 线上不需要 （要注掉）
public class EntDutyListController {

    @Autowired
    private EntDutyService entDutyService;

    /**
     * 分页查询
     * @param queryEntDutyVo
     * @return
     */
    @ApiOperation(value = "获取值班信息列表分页数据")
    @PostMapping("/getEntDutysPage")
    public HttpEntity<JsonResponse> getEntDutysPage(@ApiParam(name = "queryEntDutyVo", value = "值班表查询对象", required = true) @RequestBody QueryEntDutyVo queryEntDutyVo) {
        PageHelper.startPage(queryEntDutyVo.getPageNum(), queryEntDutyVo.getPageSize());
        List<EntDuty> list = entDutyService.selectEntDutysList(queryEntDutyVo);
        return JsonResponse.createHttpEntity(new PageInfo<>(list), HttpStatus.OK);
    }

    /**
     * 导出查询
     * @param queryEntDutyVo
     * @return
     */
    @ApiOperation(value = "获取值班信息列表全部数据")
    @PostMapping("/getEntDutysList")
    public HttpEntity<JsonResponse> getEntDutysList(@ApiParam(name = "queryEntDutyVo", value = "值班表查询对象", required = true) @RequestBody QueryEntDutyVo queryEntDutyVo) {
        List<EntDuty> list = entDutyService.selectEntDutysList(queryEntDutyVo);
        return JsonResponse.createHttpEntity(list, HttpStatus.OK);
    }


    /**
     * 批量删除
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除值班记录根据ID")
    @DeleteMapping("/deleteBatchDutysByIds/{ids}")
    public HttpEntity<JsonResponse> deleteBatchDutysByIds(@ApiParam(name = "idList", value = "主键集合", required = true) @PathVariable String ids) {
        entDutyService.deleteBatchDutysByIds(ids);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }


    /**
     * 导入
     * @param file
     * @return
     * @throws IOException
     */
    @ApiOperation(value = "通过Excel导入数据")
    @PostMapping("/importDutysExcel")
    public HttpEntity<JsonResponse> importDutysExcel(@ApiParam(name = "file", value = "导入的excel文件", required = true) MultipartFile file)  {
       List<EntDuty>   list  = ExcelUtils.readExcel(null,EntDuty.class,file);
        entDutyService.saveBatchDutys(list);
       return JsonResponse.createHttpEntity(HttpStatus.OK);

    }





}












